﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;
    using HiLand.Utility.DataBase;

    public class TemppaymentDB : BaseDB
    {
        public TemppaymentDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TemppaymentDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { 
                "INSERT INTO tEmpPayment (EmpSid,BankSid,PaymentDate,PaymentAmount,PaymentDD,PaymentMM,PaymentYY,OrgSid,InvoiceID,InvoiceDate,InvoiceStatus,other1,other2,other3,other4) VALUES (", 
                detail.EmpSid, ",", detail.BankSid, ",'", detail.PaymentDate, "',", detail.PaymentAmount, ",'", 
                StringUtils.ToSQL(detail.PaymentDD), "','", StringUtils.ToSQL(detail.PaymentMM), "','", StringUtils.ToSQL(detail.PaymentYY), "',", 
                detail.OrgSid, ",'",detail.InvoiceID,"','",detail.InvoiceDate,"',",(int)detail.InvoiceStatus,",",(int)detail.other1,",",detail.other2,",'",
                detail.ReferenceInfo,"','",detail.other4,"'",
                ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tEmpPayment where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TemppaymentDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { 
                "UPDATE tEmpPayment set EmpSid=", detail.EmpSid, ",BankSid=", detail.BankSid, ",PaymentDate='", 
                detail.PaymentDate, "',PaymentAmount=", detail.PaymentAmount, 
                ",PaymentDD='", StringUtils.ToSQL(detail.PaymentDD), "',PaymentMM='", StringUtils.ToSQL(detail.PaymentMM), 
                "',PaymentYY='", StringUtils.ToSQL(detail.PaymentYY), "',OrgSid=", detail.OrgSid, 
                ",InvoiceID='",detail.InvoiceID,"',InvoiceDate='",detail.InvoiceDate,"',InvoiceStatus=",(int)detail.InvoiceStatus,
                ",other1=",(int)detail.other1,",other2=",detail.other2,",other3='",detail.ReferenceInfo,"',other4='",detail.other4,
                " where (Sid=", detail.Sid, ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TemppaymentDT Get(int Sid)
        {
            TemppaymentDT tdt= null;
            try
            {
                try
                {
                    string strSql = "select " + TemppaymentDT.AllFields + " from tEmpPayment where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        tdt = TemppaymentDT.ConvertFrom(row);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return tdt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tEmpPayment";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

